import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/res/gaps.dart';
import 'package:ls_work/viewmodel/new_activity/activity_sign_in_view_model.dart';

class ActivitySignInListPage extends BaseStatefulMvvmWidget{
  ///1志愿者 0老人
  final int type;
  final String activityId;

  ActivitySignInListPage(this.type,this.activityId);

  @override
  State<StatefulWidget> createState() => _ActivitySignInListState();

}

class _ActivitySignInListState extends BaseMvvmListState<ActivitySignInViewModel,ActivitySignInListPage>{
  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      backgroundColor: Colors.grey[200],
      appBar: AppBar(title: Text("活动签到"),
      actions: [
        TextButton(onPressed: (){
          viewModel.scanCode();
        }, child: CommonText('扫码签到',textColor: Colors.blue))
      ],),
      body: Column(
        children: [
          Row(
            children: [
              Icon(Icons.search,color: Colors.grey,),
              Container(width: 8,),
              CommonInput(
                hintText: widget.type==1?'输入志愿者姓名搜索':'输入老人姓名搜索',
                border: InputBorder.none,
                isDense: true,
                padding: EdgeInsets.zero,
                keyboardType: CommonInputType.text,
                textInputAction: TextInputAction.search,
                onChanged: (str){
                  viewModel.searchName = str;
                },
                onSubmitted: (str){
                  viewModel.requestRefresh();
                },
              ).setWeight(1)
            ],
          ).addToContainer(
              decoration: BoxDecoration(
                color: Colors.grey[200],
                borderRadius: 20.borderRadius,
              ),
              padding: EdgeInsets.symmetric(horizontal: 10,vertical: 10)
          ).addToContainer(
              color: Colors.white,
              padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8)),
          loadingContentWidget.setWeight(1)
        ],
      ),
    );
  }

  @override
  Widget createItemWidget(int index) {
    var item = viewModel.listItems[index];
    return Row(
      children: [
        CommonText('${item.humanName}').setWeight(1),
        item.checkStatus==0?CommonText('签到',textColor: Colours.app_main).onTap(() {
          viewModel.signInActivity(item.id);
        }):
        CommonText('${item.iStatus}',textColor: Colours.app_main)
      ],
    ).addToContainer(color: Colors.white,padding: EdgeInsets.symmetric(horizontal: 16,vertical: 15));
  }

  @override
  ActivitySignInViewModel createViewModel() {
    return ActivitySignInViewModel(context,type: widget.type,activityId: widget.activityId);
  }

  @override
  EdgeInsets get listPadding => EdgeInsets.symmetric(vertical: 10);

  @override
  Widget get separatorDivider => Gaps.dividerLine;

  @override
  bool get canPullUp => false;

}